<?php
namespace Modules\Mall\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Modules\Mall\Entities\Webset;
use Modules\Mall\Http\Requests\WebsetRequest;
class WebsetController extends Controller
{
    //显示列表
    public function index()
    {
        $data = Webset::paginate(10);
        return view('mall::webset.index', compact('data'));
    }

    //创建视图
    public function create(Webset $webset)
    {
    	$w=Webset::first();
    	if($w){
    		return redirect ()->route('webset.edit',1);
		}
        return view('mall::webset.create',compact('webset'));
    }

    //保存数据
    public function store(WebsetRequest $request,Webset $webset)
    {
        $webset->fill($request->all());
        $webset->save();

        return redirect('/mall/webset')->with('success', '保存成功');
    }

    //显示记录
    public function show(Webset $field)
    {
        return view('mall::webset.show', compact('field'));
    }

    //编辑视图
    public function edit($id)
    {
    	$webset=Webset::find(1);
    	if(!$webset){
    		return redirect ()->route('webset.create');
		}
        return view('mall::webset.edit', compact('webset'));
    }

    //更新数据
    public function update(WebsetRequest $request, Webset $webset)
    {
        $webset->update($request->all());
        session()->flash('success','更新成功');
        return redirect ()->back();
    }

    //删除模型
    public function destroy(Webset $webset)
    {
        $webset->delete();
        return redirect('mall/webset')->with('success','删除成功');
    }
}
